package com.study.service;

import com.study.dao.UserAndRoleRelationsDao;
import com.study.entity.system.Role;
import com.study.entity.system.RoleAndUserRelations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户与角色绑定
 * @Author wfw
 * @Date 2020/07/13 21:57
 */
@Service
public class UserAndRoleRelationsService extends BaseService {
    @Autowired
    private UserAndRoleRelationsDao userAndRoleRelationsDao;

    @Autowired
    private RoleService roleService;

    public List<RoleAndUserRelations> findRoleByUserId(String userId){
        return userAndRoleRelationsDao.findByUserId(userId);
    }

    public List<Role> getRoleDetailByRoleId(List<String> roleIds) {
        List<Role> res = new ArrayList<>();
        for (String userAndRoleRelationId : roleIds) {
            Role role = roleService.findById(userAndRoleRelationId);
            if (!ObjectUtils.isEmpty(role)){
                res.add(role);
            }
        }
        return res;
    }
}
